/**
 * 
 */
package gui.model;

import java.awt.Component;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

/**
 * @author Christian
 * 
 */
public class HeldenListCellRenderer implements ListCellRenderer {
	
	/**
	 * 
	 */
	private DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();
	
	private int maxLength = 0;
	
	public HeldenListCellRenderer(int length) {

		this.maxLength = length;
	}
	
	/**
	 * @param list
	 *            Aktuelle Liste
	 * @param value
	 *            Wert an der Stelle
	 * @param index
	 *            Indes des Elements
	 * @param isSelected
	 *            Isselected
	 * @param cellHasFocus
	 *            HasFokus?
	 * 
	 * @return Komponente
	 */
	@Override
	public Component getListCellRendererComponent(JList list, Object value, int index,
			boolean isSelected, boolean cellHasFocus) {

		JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value,
				index, isSelected, cellHasFocus);
		if (value.toString().equals("")) {
			renderer.setText("[Namenloserheld]");
		}
		if (value.toString().length() > maxLength) {
			renderer.setText(value.toString().substring(0, maxLength - 1) + "...");
		}
		return renderer;
	}
}
